Skip to content

Reimplement 2 GameStateStructures functions at 100% from #243, plus 1 with register allocation differences - #551

Merged
TheRedDaemon merged 9 commits into
sourcehold:mainfrom
gynt:reimpl/pr243-matched
Dec 4, 2026
Merged

TheRedDaemon merged 9 commits into
sourcehold:mainfrom
gynt:reimpl/pr243-matched

Conversation

@gynt

@gynt gynt commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

This PR carries the finished part of draft PR #243 (reimpl/GameStateStructures):

  • the 2 of its 8 functions that are at 100%;
  • 1 function where only register allocation differs.

Measured on origin/main (592a17d, merged in): I built the DLL with exactly these 3 files in the build list, plus main's updateFoodTypesInStockForAllPlayers, which computePopulationStatistics calls. The struct resolvers and the function resolvers of those files were switched on, then I ran reccmp.

Function Address raw % normalized % Status
GameStateStructures::computePopulationStatistics 0x0045AF30 100.0 100.0 Reimplemented
GameStateStructures::spawnPoisonCloudsAroundBuilding 0x00459A20 100.0 100.0 Reimplemented
GameStateStructures::resetVariousCountsAndStatisticsAndStartGoodsAndResources 0x00455E10 92.9 85.5 Register allocation differs

resetVariousCountsAndStatisticsAndStartGoodsAndResources: with register names and stack offsets normalized, the code is the original's instruction for instruction (145 against 145). Several temporaries get a different volatile register (eax/ecx/edx), and that is the only difference. One side effect: ours loads one global through the shorter mov eax, [abs] encoding, so the alignment padding before the following loop is one byte longer.

Style:

  • The code follows REIMPLEMENTATION_STYLE_GUIDE.md.
  • Map bounds use MC_MAP_XY_LIMIT_MIN_1/MC_MAP_XY_LIMIT.
  • The logic-layer mask is spelled as Logic1 flags (L_SEA | L_BORDER | ... | L_MOAT == 0x4a5014b1).
  • Loop bounds use countof.
  • BOOLEnum values are tested directly.
  • Unused usings are removed.
  • Forms that are kept only for the match are explained in a comment on this PR.

Header changes, /GL and function-visibility entries: none.

Left in #243:

  • processFoodConsumption and updateCrowding are both at 100% in the draft, but they reach it only through a local PLAYER_FIELD #define. It walks an int* through PlayerData the way the original does. A PlayerData* walk does not match, so they are kept out of this PR and go to a separate PR for match-driven forms.
  • computeBuildingCategoryEntryPointAndDestroyEarlierBuilding (84.8): the stores to PlayerData fields are in a different order.
  • processPeasantSpawnAndDespawnCycle (85.3): it has extra field stores and a lea where the original uses repeated adds.
  • spawnMotherOrChild (54.6): a different frame and induction variables.

Overlap with open PRs: none outside #243 itself.

There is one commit per function, with its line in status/addresses-SHC-3BB0A8C1.txt, plus a style: and a review: commit.

Draft PR #243 stays open for the remaining functions.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp

gynt and others added 9 commits December 4, 2026 15:15
As in sourcehold#243: the original keeps this in edx across the call to updateFoodTypesInStockForAllPlayers, which is already /GL on main. LTCG can only reproduce that with both sides compiled /GL (96.5% without the entry, 100% with it).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
countof instead of the loop bounds 9, 8, 300 and 299; the logic-layer mask in spawnPoisonCloudsAroundBuilding as Logic1 flags (L_SEA | L_BORDER | ... | L_MOAT == 0x4a5014b1); BOOLEnum fields and returns tested directly instead of against FALSE; const on the two assign-once locals of resetVariousCounts...; duplicate own .func.hpp include and unused usings dropped; namespace closing comments.
Re-measured on 40cbb1c with a full build and reccmp: the four 100% functions stay 100.0/100.0, resetVariousCountsAndStatisticsAndStartGoodsAndResources stays 92.9/85.5 (register-blind identical).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
- processFoodConsumption and updateCrowding leave this PR: they only match through a local PLAYER_FIELD #define that walks an int pointer through PlayerData (a PlayerData* walk measures 0.48 in quick_diff). Their status lines go back to main's, and so does the /GL entry processFoodConsumption needed.
- spawnPoisonCloudsAroundBuilding: map bounds as MC_MAP_XY_LIMIT_MIN_1 / MC_MAP_XY_LIMIT, the logic mask tested by truthiness, const on the two positions, and the match-explaining comment removed (moved into the PR thread).
Re-measured on 592a17d with a full build and reccmp: computePopulationStatistics and spawnPoisonCloudsAroundBuilding 100.0/100.0, resetVariousCountsAndStatisticsAndStartGoodsAndResources 92.9/85.5 (register-blind identical).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@gynt gynt changed the title Reimplement 4 GameStateStructures functions at 100% from #243, plus 1 with register allocation differences Reimplement 2 GameStateStructures functions at 100% from #243, plus 1 with register allocation differences Dec 4, 2026
@gynt

gynt commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Forms in this PR that are kept only for the match:

  • spawnPoisonCloudsAroundBuilding: attemptsLeft-- is written in each of the two failure branches, not in the for header. With the decrement in the header, quick_diff drops from 99.4 to 96.1 (reccmp 100 → below 100). The original does a read-modify-write on the stack slot in each branch.
  • resetVariousCountsAndStatisticsAndStartGoodsAndResources: isSkirmishTrail == TRUE stays an explicit comparison. Plain truthiness emits test/je instead of the original's cmp 1/jne, so the original really compares against 1.
  • computePopulationStatistics / resetVarious...: the (short) casts on assignments into short fields narrow an int, so they are needed.

@TheRedDaemon
TheRedDaemon added this pull request to the merge queue Dec 4, 2026
Merged via the queue into sourcehold:main with commit c9a2827 Dec 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants